﻿using UnityEngine;
using System.Collections;
namespace net{
	public class RemoteBomb : MonoBehaviour {
		
		AudioSource audioSource;
		Animator anim;	

		public void playAudio(){
			audioSource = GetComponent<AudioSource> ();
			audioSource.clip = Resources.Load("mp3/bomb") as AudioClip;
			 
			audioSource.Play ();
			 
		}
		
		[RPC]
		public void playVoice(){
				playAudio();
		}

		[RPC]
		public void playAnmi(){
			anim = GetComponent<Animator> ();
			anim.StopPlayback ();
			anim.Play ("bomb");
		}

		[RPC]
		public void playFail(NetworkViewID id){
			 GameObject Mybase = NetworkView.Find(id).gameObject;
			if(Mybase.networkView.isMine){
			    audioSource = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<AudioSource>();
				audioSource.clip = Resources.Load("mp3/fail") as AudioClip;
				audioSource.Play();
			}
		}

		[RPC]
		public void callReborn(NetworkViewID  id){
			GameObject obj =  NetworkView.Find(id).gameObject;
			if(obj.networkView.isMine){
				obj.GetComponent<NetPlayerState>().isAlive = false;
				GameObject.FindGameObjectWithTag("MainCamera").transform.GetComponent<NetMain>().rebornAfterSec(2);// 2s后复活
				GameObject btn = GameObject.FindGameObjectWithTag("LEVELUPBTN");
				btn.transform.localScale = new Vector3(0,0,0);

			}
		}

		[RPC]
		public void destroyFrag(NetworkViewID id, string name){
			GameObject brick = NetworkView.Find(id).gameObject;
			//if(!brick.networkView.isMine){
			foreach (Transform child in brick.transform) {
				if (child.name.Equals(name)) {
					Destroy(child.gameObject);
				//	print ("rpc destroy " + child.name);
				}
			}
			//}
		}
	}
}